package  
{
	import org.flixel.*;
	import org.flixel.plugin.photonstorm.FlxExtendedSprite;
	import org.flixel.plugin.photonstorm.FlxMouseControl;
	import org.flixel.plugin.photonstorm.FlxCollision;
	
	/**
	 * ...
	 * @author ...
	 */
	public class ASGamePrototype extends ExtendedFlxState
	{
		private const rotateSpeed:Number = 1.5;
		
		private var puzzlePieces:FlxGroup;
		private var lastSelectedPiece:FlxExtendedSprite;
		
		//private var temp:FlxExtendedSprite;
		private var temp:FlxSprite;
		private var tempText:FlxText;
		
		public function ASGamePrototype() 
		{
			puzzlePieces = new FlxGroup();
			
			//temp = new FlxExtendedSprite(50, 50);
			//temp.makeGraphic(80, 250, 0xFFEFD0CF);
			//temp.enableMouseDrag(false, true);
			//temp.boundsRect = new FlxRect(10, 10, FlxG.width - 20, FlxG.height - 20);
			
			temp = new FlxSprite(50, 50);
			//temp.makeGraphic(80, 250, 0xFFEFD0CF);
			temp.loadRotatedGraphic(ImageFiles.body, 128, -1, true, true);
			
			puzzlePieces.add(temp);
			
			add(puzzlePieces);
			
			tempText = new FlxText(10, 10, 500).setFormat(null, 18, Color.Green);
			add(tempText);
		}
		
		override public function update():void 
		{
			super.update();
			
			if (FlxCollision.pixelPerfectPointCheck(FlxG.mouse.screenX, FlxG.mouse.screenY, temp))
			{
				tempText.text = "yes";
			}
			else
			{
				tempText.text = "no";
			}
			
			if (FlxMouseControl.dragTarget != null)
			{
				lastSelectedPiece = FlxMouseControl.dragTarget;
				puzzlePieces.remove(FlxMouseControl.dragTarget, true);
				puzzlePieces.add(lastSelectedPiece);
			}
			
			temp.angularVelocity = 0;
			
			if (FlxG.keys.pressed("A") || FlxG.keys.pressed("LEFT"))
			{
				temp.angle -= rotateSpeed;
			}
			
			if (FlxG.keys.pressed("D") || FlxG.keys.pressed("RIGHT"))
			{
				temp.angle += rotateSpeed;
			}
		}
	}
}